package com.zmovie.front.util;

import com.alibaba.fastjson.JSON;
import com.zmovie.common.utils.FileUtils;
import com.zmovie.framework.domain.Movie;
import com.zmovie.front.controller.vo.MovieVO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 处理图片路径
 * @since 2023-12-15 13:04
 */
public class MoviePathUtil {
    public static List<MovieVO> dealMovieFilePath(List<Movie> movies){
        return movies.stream().map(MoviePathUtil::dealMovieFilePath).collect(Collectors.toList());
    }
    public static MovieVO dealMovieFilePath(Movie movie){
        MovieVO movieVO = new MovieVO();
        BeanUtils.copyProperties(movie, movieVO);
        //封面
        String posterJsonList = movie.getPoster();
        List<String> posterList = JSON.parseArray(posterJsonList, String.class);
        if(posterList.size() > 0)
            movieVO.setPoster(FileUtils.dealFilePath(posterList.get(0)));
        //图集
        List<String> pictures = JSON.parseArray(movie.getPictures(), String.class);
        List<String> newPaths = pictures.stream().map(FileUtils::dealFilePath).collect(Collectors.toList());
        movieVO.setPictureList(newPaths);
        return movieVO;
    }
}
